<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>4_函数组件使用props</title>
</head>
<body>
  <div id="test01"></div>
  <div id="test02"></div>
  <div id="test03"></div>

  <script src="../js/react.development.js"></script>
  <script src="../js/react-dom.development.js"></script>
  <!-- Don't use this in production: -->
  <script src="../js/babel.min.js"></script>
  <!-- 引入prop-types.js  用于对组件标签属性进行限制 -->
  <script src="../js/prop-types.js"></script>

  <script type="text/babel">
    // 创建组件
    function Person (props) {
      const {name, sex, age} = props
      return (
        <ul>
          <il>姓名：{name}</il>
          <li>性别：{sex}</li>
          <li>年龄：{age + 1}</li>
        </ul>
      )
    }

    Person.propTypes = {
      name: PropTypes.string.isRequired,  //  限制name必传，且为字符串
      sex: PropTypes.string,              //  限制sex为字符串
      age: PropTypes.number,              //  限制age为数值
      speak: PropTypes.func               //  限制speak为函数
    }

    Person.defaultProps = {
      sex: '男',  //  sex默认值为男
      age: 18           //  age默认值为18
    }

    // 渲染组件到页面
    ReactDOM.render(<Person name="朱元璋" sex="男" age={18} />, document.getElementById("test01"))

  </script>
</body>
</html>